import { realTimeBasicApi } from './service';

import { ModelType } from '@/common-typings.d';

const Model: ModelType = {
  namespace: 'statistics',
  state: {
    basic: {},
  },

  effects: {
    // 取得实时统计-基础数据
    *getBasicEffect({ payload, callback }, { call, put }) {
      const response = yield call(realTimeBasicApi, payload);
      yield put({ type: 'setBasic', payload: response.data, callback });
    },
  },

  reducers: {
    setBasic(state, { payload }) {
      const newState = JSON.parse(JSON.stringify(state));
      newState.basic = payload;
      return newState;
    },
  },
};

export default Model;
